<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 {width: 200px; height: 200px; background: yellow; position: absolute;}	
</style>
<script>
	var oDiv = null;
	var disX= 0 ;
	var disY = 0;
	
window.onload=function()
{
		oDiv = document.getElementById('div1');
		oDiv.onmousedown=Down;
};
	

	function Down(ev)
	{
			var oEvent = ev || event;

			disX = oEvent.clientX-oDiv.offsetLeft;
		 disY = oEvent.clientY  - oDiv.offsetTop;

			document.onmousemove = Move;
			
			document.onmouseup = up ;
				
	}
	
function Move (ev)
{
		var oEvent = ev || event;

		oDiv.style.left = oEvent.clientX-disX + 'px';
		oDiv.style.top = oEvent.clientY -disY + 'px';
}
	
	function up()
	{
			document.onmousemove =null;
			document.onmouseup = null;
	}

</script>
</head>

<body>
<div id="div1"></div>
</body>
</html>
